package leetcode_core.leetcode_1;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class FourKey {

    private Map<String, Integer> map = new HashMap<>();

    int dp(int n,int aNum,int copy){
        if(n<=0){
            return aNum;
        }
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(n+",");
        stringBuilder.append(aNum+",");
        stringBuilder.append(copy);
        if(map.get(stringBuilder.toString())!=null){
            return map.get(stringBuilder.toString());
        }
        int op1 = dp(n-1,aNum+1,copy);//按下A键
        int op2 = dp(n-1,aNum+copy,copy);//进行粘贴
        int op3 = dp(n-2,aNum,aNum);
        map.put(stringBuilder.toString(),Math.max(Math.max(op1,op2),op3));
        return map.get(stringBuilder.toString());
    }

    int maxA(int n){
        int[] dp = new int[n+1];
        dp[0]=0;
        for(int i = 1;i<=n;i++){
            dp[i] = dp[i-1]+1;
            for(int j=2;j<i;j++){
                dp[i]=Math.max(dp[i],dp[j-2]*(i-j+1));//一共有i-j次复制粘贴,+1是包括自己
            }
        }
        return dp[n];
    }
    @Test
    public void test(){
        System.out.println(maxA(3));
        System.out.println(maxA(7));
    }
}
